<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class ForgetPassword extends Controller
{
    public function forget(){
        return view('forgetPassword.forget');
    }
    public function sendEmail(Request $request){
        $post = $request->all();
        $user = User::where('email',$post['email'])->first();
        if($user){
//            这时候发送邮件
            \Notification::send($user,new \App\Notifications\forgetPassword($user['email']));
            session()->flash('success','邮件已发送成功');
            return view('forgetPassword.sendOk');
        }
    }
    public function changePass($email){
        return view('forgetPassword.changPassword',compact('email'));
    }
    public function change(Request $request){
        $post = $request->all();
        $validator = $request->validate(
          [
              'password' => 'required|between:6,12|confirmed',
              'password_confirmation'=>'required|between:6,12'
          ]
        );
        $user = User::where('email',$post['email'])->first();
        $user->password = bcrypt($post['password']);
        $user->save();
        session()->flash('success','修改成功');
        return redirect('/login');
    }
}
